<template>
  <div style="">
    <!-- <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item @click.native="$router.back()">{{$route.query.flag=='examine'?'审批列表':'项目列表'}}</el-breadcrumb-item>
      <el-breadcrumb-item >项目详情</el-breadcrumb-item>
    </el-breadcrumb> -->
    <h2 style="width: 100%;text-align: center;padding-bottom: 20px;">{{assessInfo.title}}</h2>
    <project-template :flag="'projectdetail'" :readonly='true' v-if="show"  :assessInfo='assessInfo' :showPdf='true' :answerInfoList='answerInfoList' :pdfList='pdfList'></project-template>
  </div>
</template>

<script>
  import projectTemplate from "@/components/projectTemplate.vue"
  import axios from "axios"
  export default{
    name: "projectdetails",
    data(){
      return{
        assessInfo:{
          task:[]
        },
        resultList:[],
        pdfList:[],
        answerInfoList:[],
        show:true
      }
    },
    components:{
      projectTemplate
    },
    methods:{
      async initPage(){
        let str=this.$route.query.flag=='user'?'/api/result/detail/'+this.$route.query.id:'/api/approval/result?pId='+this.$route.query.id+'&uId='+this.$route.query.uId
        // let assessInfoRes= await this.$get('/api/project/'+this.$route.query.id)
        let result= await this.$get(str)
        if(result.code==200){
          result.data.results.map(item=>this.assessInfo.task.push(item.task))
          this.answerInfoList=result.data.results
          this.assessInfo.task.forEach((item,index)=>{
            if(item.isFile) {
              this.pdfList[index]=[]
            }
          })
          this.answerInfoList.map((item,index)=>{
            // if(index==0&&item.evidenceList.length!=0)this.show=true
            if(this.pdfList[index]!=undefined) this.pdfList[index]=item.evidenceList
          })
          // result.data.task.forEach((item,index)=>{
          //    if(item.isUpload) {
          //     this.pdfList[index]=[]
          //   }
          // })
          // //获取promise集合 按顺序请求pdf文件
          // let promiseArr=[]
          // let tempArr=[]
          // result.data.result.evidenceList.forEach(item=>{
          //   let count=0
          //   item[Object.keys(item)[0]].forEach((items,index)=>{
          //     promiseArr.push(this.getStagingPdf(items))
          //     count++
          //   })
          //   tempArr.push(count)
          // })
          // Promise.all(promiseArr).then(res=>{
          //   let index=0
          //   for(let item=0;item<this.pdfList.length;item++){
          //     if(this.pdfList[item]!=undefined){
          //       let count=0
          //       console.log(this.pdfList[item])
          //       for(let i=0; i< tempArr[index];i++){
          //         this.pdfList[item].push(res[count])
          //         count++
          //       }
          //       index++
          //     }
          //   }
          //   this.show=false
          //   this.$nextTick(()=>{
          //     this.show=true
          //   })
          // })
        }
      },
      getStagingPdf(urlVal){
        return new Promise(resolve=>{
         axios({
           url:'/api'+urlVal,
           method:'get',
           responseType: 'blob',
           headers: {
             'content-type': 'application/json;charset=UTF-8'
           },
         }).then(res=>{
          resolve(res)
         })
        })
      },
    },
    mounted(){
      // this.setTabs('sys:project:details')
      this.initPage()
    }
  }
</script>

<style>
</style>
